﻿$.ajaxSetup({ url: "ListSensorList.aspx", type: "post", dataType: "json" });
var pageIndex = 0;
var pageSize = 20;
var page_count = 0;

function delSensorById(pmSensorId) {

    if (!confirm("真的要删除吗?"))
        return ;
    $.ajax({
        data: { method: "DeleteSensor",
            sensorId: pmSensorId
        }
        , success: function (json) {
            alert(json.ListSensor);
            btnSearch_Click();
        }
    });
}


function btnSearch_Click() {

    var meteredNo = $("#txtMeteredNo").val();
    var parkingNo = $("#txtParkingNo").val();
    var name = $("#txtName").val();
    var longitude = $("#txtLongitude").val();
    var latitude = $("#txtLatitude").val();
    var streetCode = $("#txtStreetCode").val();
    var inducedScreenNo = $("#txtInducedScreenNo").val();

    $.ajax({
        data: { method: "ListSensor",
            meteredNo: meteredNo,
            parkingNo: parkingNo,
            name: name,
            longitude: longitude,
            latitude: latitude,
            streetCode: streetCode,
            inducedScreenNo: inducedScreenNo,
            page: pageIndex,
            size: pageSize
        }
        , success: function (json) {
            // 先删除原来的行，否则会多次绑定。
            $("#tbl_ListSensor tr").each(function (trindex, tritem) {
                if (trindex != 0)
                    $(tritem).remove();
            });
            // 填充表格
            $("#tbl_ListSensor").append("#full_ListSensor", json.ListSensor);
            // 分页
            page_count = Math.ceil(json.RowsCount / pageSize);
            PagerInit();
        }
    });
}

function PagerInit() {
    $(document).ready(function () {
        $("#pager").pager({ pagenumber: pageIndex, pagecount: page_count, buttonClickCallback: PageClick });
    });
}
function PageClick(pageclickednumber) {
    $("#pager").pager({ pagenumber: pageclickednumber, pagecount: page_count, buttonClickCallback: PageClick });
    pageIndex = pageclickednumber;
    btnSearch_Click();
}

function init() {
    btnSearch_Click();
    $("#btnSearch").click(function () {
        btnSearch_Click();
    });
}

